/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.android.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shwread.android.qysw10000182.R;

import logic.util.PicassoUtil;
import logic.util.Util;


/**
 * @Project： Lqyd_Android
 * @Title：DownloadDialog
 * @Description：
 * @Author：wayne
 * @Date：2014年8月26日上午3:42:59
 */
public class DownloadDialog
        extends
        Dialog
{
	private DownLoadDialogClickListener dialogListener;
	private LayoutInflater                 mInflater;
	private Context                        mContext;
	private TextView                       tvBookName, tvBookSize, tvCancle, tvConfirm;
	ImageView ivBookImg;
	String                                 name;
	String                                 size;
	int                                    resId;
	String                                 url;
	long                                   contentId;
	Context                                context;
	
	public DownloadDialog(Context context) {
		super(context, R.style.common_dialog);
		mInflater = LayoutInflater.from(context);
		this.context = context;
	}
	
	public void setMessage(String name, String size, int resId) {
		this.name = name;
		this.size = size;
		this.resId = resId;
	}
	
	public void setMessage(String name, String size, String logoUrl, long contentId) {
		this.name = name;
		this.size = size;
		url = logoUrl;
		this.contentId = contentId;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = mInflater.inflate(R.layout.book_download_lay, null);
		setContentView(view);
		tvBookName = (TextView) view.findViewById(R.id.book_name);
		tvBookSize = (TextView) view.findViewById(R.id.book_size);
		ivBookImg = (ImageView) view.findViewById(R.id.book_img);
		tvCancle = (TextView) view.findViewById(R.id.cancle);
		tvConfirm = (TextView) view.findViewById(R.id.confirm);
		tvConfirm.setOnClickListener(okListener);
		tvCancle.setOnClickListener(cancelListener);
		tvBookName.setText(name);
		tvBookSize.setText("书籍大小：" + Util.formetFileSize(Long.valueOf(size)));
//		ivBookImg.setImageUrl(url);
		PicassoUtil.load(context,url,R.drawable.bookcover_default, ivBookImg);


		getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		getWindow().setGravity(Gravity.BOTTOM);
		getWindow().setWindowAnimations(android.R.style.Animation_InputMethod);
		
	}
	
	private View.OnClickListener okListener     = new View.OnClickListener()
	                                            {
		                                            
		                                            @Override
		                                            public void onClick(View v) {
			                                            dialogListener.okListener(v);
		                                            }
	                                            };
	
	private View.OnClickListener cancelListener = new View.OnClickListener()
	                                            {
		                                            
		                                            @Override
		                                            public void onClick(View v) {
			                                            dialogListener.cancelListener(v);
		                                            }
	                                            };
	
	public void setPageListener(DownLoadDialogClickListener dialogListener) {
		this.dialogListener = dialogListener;
	}
	
	public interface DownLoadDialogClickListener
	{
		public void okListener(View v);
		
		public void cancelListener(View v);
	}
}
